<?php
/**
 * @filename TestZip.php
 * @author LD King
 * @encoding UTF-8
 * @date 2008-9-10 | 上午12:30:22
 * @package wp-simple-backup
 * @subpackage test
 * @usage 测试 PHP 5.2 ZIP 压缩
 * @note 
 * @copyright Copyright (c) 2007 - 2008 LD (http://mifunny.info)
 * @version $Id: $
 */

/**
 * 把文件/目录加入 $zip 对象
 *
 * @var string $path, ZipArchive $zip
 */
function addFileToZip(ZipArchive $zip, $path, $exclude) {
	/**
	 * 迭代方法
	 */
	$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), true);
	
	/**
	 * 循环添加文件
	 */
	foreach ($dir as $key => $value) {
		if (is_dir($value)) {
			$zip->addEmptyDir($value);
		}else {
			$zip->addFile($value);
		}
	}
}



$zip = new ZipArchive();
echo "new ZipArchive()<br />";

if ($zip->open('bp/TestZip.zip', ZipArchive::OVERWRITE) === TRUE) {
	$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('/home/http/mifunny'), true);
	/*foreach ($dir as $key => $value) {
		echo str_repeat('|─', $dir->getDepth()).$value.'<br />';
		if (is_dir($value)) {
			$zip->addEmptyDir(preg_replace('/\/home\/http\//', '', $value));
		}else {
			$zip->addFile($value, preg_replace('/\/home\/http\//', '', $value));
		}
	}*/

/*	if ($zip->addFile('TestZip.php') == false)
		echo "Zip FALSE!<br />";
	else echo "Zip TRUE!<br />";*/
} else {
	echo "Open FALSE!<br />";
}

$zip->close();
?>